// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   SongChooser.java

package presenter;

import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.util.Arrays;
import javax.swing.*;
import javax.swing.plaf.basic.BasicInternalFrameUI;

// Referenced classes of package presenter:
//            SongFile

public class SongChooser extends JInternalFrame
    implements MouseListener
{

    public SongChooser()
    {
    }

    public SongChooser(File f)
    {
        if(f.isDirectory())
        {
            File s[] = f.listFiles();
            File songs[] = new File[s.length];
            int index = 0;
            for(int i = 0; i < s.length; i++)
                if(!s[i].isDirectory())
                {
                    songs[index] = s[i];
                    index++;
                }

            this.songs = new SongFile[index];
            for(int i = 0; i < s.length; i++)
                this.songs[i] = new SongFile(songs[i]);

            Arrays.sort(this.songs);
            songList = new JList(this.songs);
            scrollPane = new JScrollPane();
            scrollPane.getViewport().setView(songList);
            scrollPane.setVisible(true);
            add(scrollPane);
            songList.addMouseListener(this);
            songToAdd = false;
        }
        try
        {
            ((BasicInternalFrameUI)getUI()).getNorthPane().setPreferredSize(new Dimension(0, 0));
        }
        catch(Exception e) { }
    }

    public boolean isSongToAdd()
    {
        return songToAdd;
    }

    public SongFile getSongAdding()
    {
        songToAdd = false;
        return songAdding;
    }

    public SongFile[] getSongs()
    {
        return songs;
    }

    public boolean isUpdated()
    {
        if(update)
        {
            update = false;
            return true;
        } else
        {
            return false;
        }
    }

    public SongFile getSelected()
    {
        return songs[songList.getSelectedIndex()];
    }

    public void mouseClicked(MouseEvent mouseevent)
    {
    }

    public void mousePressed(MouseEvent me)
    {
        requestFocusInWindow();
        update = true;
        if(me.getClickCount() == 2)
        {
            int index = songList.locationToIndex(me.getPoint());
            songToAdd = true;
            songAdding = songs[index];
        }
    }

    public void mouseReleased(MouseEvent mouseevent)
    {
    }

    public void mouseEntered(MouseEvent mouseevent)
    {
    }

    public void mouseExited(MouseEvent mouseevent)
    {
    }

    JList songList;
    JScrollPane scrollPane;
    SongFile songs[];
    boolean songToAdd;
    private SongFile songAdding;
    private boolean update;
}
